<?php
/**
 * 用户信息管理
 */
class usertypeAction extends backendAction
{

    public function _initialize() {
        parent::_initialize();
        $this->_mod = D('usertype');
		$catelist = M('item_cate')->where(array('pid'=>0))->select();
		$this->assign('catelist', $catelist);
    }
/*
	public function index() {
		$list = $this->_mod->order('id desc')->limit('0, 10')->select();
		foreach($list as $key=>$v){
			if($v['type']=='汽车膜'){
				if(strstr($v['tiaojian'], "及以上")){
					$tiaojian = str_replace("及以上","",$v['tiaojian']);
					$tiaojian .= "套及以上";
				}else{
					$tiaojian = $v['tiaojian']."套";
				}
			}
			if($v['type']=='建筑膜'){
				if(strstr($v['tiaojian'], "及以上")){
					$tiaojian = str_replace("及以上","",$v['tiaojian']);
					$tiaojian .= "㎡及以上";
				}else{
					$tiaojian = $v['tiaojian']."㎡";
				}
			}
			$list[$key]['tiaojian'] = $tiaojian;
		}
		
		 $this->assign('list', $list);
		$this->display();
	}


	public function edit(){
		$id = $this->_request('id', 'intavl');
		if($_POST){
			
		}else{
			$item = $this->_mod->where(array('id'=>$id))->find();
			if($item){
				if(strstr($item['tiaojian'], "及以上")){
					$item['tiaoajian'] = array(str_replace("及以上", '', $item['tiaojian']), '999999999');
				}else{
					$item['tiaojian'] = explode('-', $item['tiaojian']);
				}
			}
			
			$this->assign('info', $item);
			$this->display();
		}
	}
*/

    protected function _search() {
        $map = array();
        if( $keyword = $this->_request('keyword', 'trim') ){
            $map['_string'] = "username like '%".$keyword."%' OR email like '%".$keyword."%'";
        }
        $this->assign('search', array(
            'keyword' => $keyword,
        ));
        return $map;
    }

    public function _before_index() {
        $big_menu = array(
            'title' => L('添加'),
            'iframe' => U('usertype/add'),
            'id' => 'add',
            'width' => '500',
            'height' => '330'
        );
        $this->assign('big_menu', $big_menu);
    }

    public function add_users(){
        if (IS_POST) {
            $users = $this->_post('username', 'trim');
            $users = explode(',', $users);
            $password = $this->_post('password', 'trim');
            $gender = $this->_post('gender', 'intavl');
            $reg_time= time();
            $data=array();
            foreach($users as $val){
                $data['password']=$password;
                $data['gender']=$gender;
                $data['reg_time']=$reg_time;
                if($gender==3){
                    $data['gender']=rand(0,1);
                }
                $data['username']=$val;
                $this->_mod->create($data);
                $this->_mod->add();
            }
            $this->success(L('operation_success'));
        } else {
            $this->display();
        }
    }


    /**
     * ajax检测会员是否存在
     */
    public function ajax_check_name() {
        $name = $this->_get('username', 'trim');
        $id = $this->_get('id', 'intval');
        if ($this->_mod->name_exists($name,  $id)) {
            $this->ajaxReturn(0, '该会员已经存在');
        } else {
            $this->ajaxReturn();
        }
    }

}